Skip to content

fix(openai): strip pattern keyword from Responses API schemas (zod v4 compat)#16521

Open
FrancoKaddour wants to merge 3 commits into
vercel:mainfrom
FrancoKaddour:fix/openai-responses-strip-pattern-keyword
Open

fix(openai): strip pattern keyword from Responses API schemas (zod v4 compat)#16521
FrancoKaddour wants to merge 3 commits into
vercel:mainfrom
FrancoKaddour:fix/openai-responses-strip-pattern-keyword

Conversation

@FrancoKaddour

Copy link
Copy Markdown

Fixes #16021

zod v4's toJSONSchema() emits pattern for string validators like z.email(), z.uuid(), and z.iso.date(). These patterns contain regex features (e.g. lookaheads) that OpenAI's structured outputs API does not support, causing a server_error response.

This strips the pattern keyword recursively from schemas sent to the Responses API — both in response format text.format.schema) and in tool parameters — before the request is made.

@FrancoKaddour FrancoKaddour marked this pull request as draft June 30, 2026 18:48
Comment thread packages/openai/src/responses/openai-responses-sanitize-schema.ts
Recurse only through known JSON Schema structural keywords (properties,
patternProperties, \, allOf, anyOf, etc.) instead of every object key.
Prevents deletion of user-defined tool or response parameters whose name
happens to be 'pattern'.
@FrancoKaddour FrancoKaddour marked this pull request as ready for review June 30, 2026 22:15
…types

The function returned unknown, causing a tsc error when assigned to the
strongly-typed parameters: JSONSchema7 field of OpenAIResponsesFunctionTool.
Using a generic <T> preserves the input type through the return value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Responses API: in-stream server_error triggered by zod v4 string-format regex patterns in tool schemas (gpt-5.4)

1 participant